# -*- coding: utf-8 -*-
# @Time    : 2021/8/30 23:18
# @Author  : BrandonGT
# @FileName: 04_PyQt5_QWidget_交互状态_案例.py

import sys
from PyQt5.QtWidgets import *


class Window(QWidget):
    def __init__(self):
        super().__init__()  # 初始化继承的父类内部的__init__
        self.setWindowTitle("交互状态案例的学习")
        self.resize(300, 300)
        self.setup_ui()


    def setup_ui(self):
        self.le = QLabel(self)
        self.le.resize(100, 50)
        self.le.setText("登录")
        self.le.move(100, 50)
        self.le.hide()

        self.line = QLineEdit(self)
        self.line.resize(100, 20)
        self.line.move(100, 100)
        self.line.textChanged.connect(self.tx_change)

        self.btn = QPushButton(self)
        self.btn.resize(100, 20)
        self.btn.setText("登录")
        self.btn.move(100, 150)
        self.btn.setEnabled(False)
        self.btn.clicked.connect(self.btn_clicked)

    def tx_change(self):
        # print("text changed")
        self.btn.setEnabled(len(self.line.text()) > 0)

    def btn_clicked(self):
        if self.line.text() == "bd":
            self.le.setText("登录成功")
        else:
            self.le.setText("登录失败")

        self.le.show()


if __name__ == '__main__':
    app = QApplication(sys.argv)
    window = Window()
    window.show()
    sys.exit(app.exec_())